package qnb.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import qnb.dao.NoticeDao;
import qnb.entity.Notice;
import qnb.service.NoticeService;
@Service
public class NoticeServiceImpl implements NoticeService {
	@Autowired
	private NoticeDao noticeDao;


	@Override
	public int add(Notice notice) {
		notice.setNoticeId(null);
		notice.setNoticeCreated(new Date());
		notice.setNoticeUpdated(notice.getNoticeCreated());

		return noticeDao.add(notice);

	}

	@Override
	public int delete(Integer id) {
		return noticeDao.deleteByPrimaryKey(id);
	}

	@Override
	public int update(Notice notice) {
		notice.setNoticeCreated(null);
		notice.setNoticeUpdated(new Date());
		return noticeDao.update(notice);
	}


	@Override
	public List<Notice> selectAll() {
		return noticeDao.selectAll();
	}

	@Override
	public Notice getText(Integer id) {
		if (id<0){
			return noticeDao.getNewNotice();
		}else{
			return noticeDao.getText(id);
		}
	}

}
